<?php
class followup extends ci_controller
{

	function __construct(){
		
		parent::__construct();
		$this->load->library('tank_auth');
		$this->load->library('bamer_lib');
		$this->load->model('modul/followup_model');
		$this->load->model('user');

		if (!$this->tank_auth->is_logged_in()) redirect('/auth/login/');
		$this->load->helper('bamer_helper');
		$this->lang->load('tank_auth');
		
	}

	function index(){

		//check_permission
		$this->bamer_lib->check_permission_show($this->tank_auth->get_user_id(), 'followup');
		$id_t = $this->tank_auth->get_user_id();
		//end
		$id_g = $this->followup_model->get_id_global($id_t);
		$data['rows_penugasan_followup'] = $this->followup_model->list_penugasan_followup($id_g);
		$data['menu'] = 'halaman kerja';
		$data['head'] = 'layout/head';
        $data['navbar'] = 'layout/navbar';
		$data['content'] = 'modul/followup/index';
		$this->load->view('layout/inner', $data);
	}


	function edit(){
		//check_permission
		$this->bamer_lib->check_permission_update($this->tank_auth->get_user_id(), 'followup');
		//end

		$id = $this->uri->segment(4);

		$data['get_penugasan_followup_detail'] = $this->followup_model->isi_penugasan_followup($id);
		
		$data['menu'] = 'halaman kerja';
		$data['head'] = 'layout/head';
        $data['navbar'] = 'layout/navbar';
		$data['content'] = 'modul/followup/edit';
		$this->load->view('layout/inner', $data);
	
	}

	function update(){
		//check_permission
		$this->bamer_lib->check_permission_update($this->tank_auth->get_user_id(), 'followup');
		//end
		$id_t = $this->tank_auth->get_user_id();
		//validation
		$this->form_validation->set_rules('deskripsi_followup', 'Deskripsi followup', 'trim|required|min_length[3]|xss_clean');
		
		if ($this->form_validation->run() == FALSE)
		{
			
		//end
				$id_g = $this->followup_model->get_id_global($id_m);
				$data['rows_penugasan_followup'] = $this->followup_model->list_penugasan_followup($id_g);
				$data['menu'] = 'halaman kerja';
				$data['head'] = 'layout/head';
		        $data['navbar'] = 'layout/navbar';
				$data['content'] = 'modul/followup/index';
				$this->load->view('layout/inner', $data);
		}
		else
		{
				$date = get_date_time();
				$data_followup = array(
				'deskripsi_hasil_followup' => $this->input->post('deskripsi_followup'),
				'waktu_followup' => $date,
				);

			$where_penugasan_followup = array('id_penugasan_followup' => $this->input->post('id_penugasan_followup'));
			$this->user->update('penugasan_followup',$where_penugasan_followup, $data_followup);

				$data_status_marketing = array(
				'status_marketing_perusahaan' => $this->input->post('status_marketing'), 
				);
			$where_status_marketing = array('id_perusahaan' => $this->input->post('id_perusahaan'));
			$this->user->update('perusahaan',$where_status_marketing, $data_status_marketing);
			redirect('modul/followup/index');
		}

	}
}
?>